/**
 * 组合促销价格维护 - 详情页面
 * @author shixc
 * @date 2019/03/05
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        vueData = {
            form: '',
            rules: {
                GWDC001: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC003: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC005: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC007: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC009: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWDC010: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions: {
                gwdc005Options: app.datas_('crm_gwcd_gwcd005'),
                gwdc006Options: app.datas_('crm_gwcd_gwcd006'),
                gwdc007Options: app.datas_('crm_gwcd_gwcd007')
            }
        },
        cols1 = [[
            {field: 'GWDC002', type: 'checkbox', title: '选择'}
            , {field: 'GWDC016', width: 80, title: '客户编号'}
            , {field: 'GWDC017', width: 80, title: '客户名称'}
            , {field: 'GWDC018', width: 120, title: '品号'}
            , {field: 'GWAML003', width: 120, title: '品名'}
            , {field: 'GWAML004', width: 120, title: '规格'}
            , {field: 'GWDC019', width: 80, title: '单位说明'}
            , {field: 'GWDC023', width: 80, title: '结算价'}
            , {field: 'GWDC024', width: 80, title: '活动价格'}
        ]],
        cols2 = [[
            {field: 'GWDCZ002', type: 'checkbox', title: '选择'}
            , {field: 'GWDCZ003', width: 80, title: '序号'}
            , {field: 'GWDCZ004', width: 80, title: '赠品品号'}
            , {field: 'GWAML003', width: 120, title: '赠品品名'}
            , {field: 'GWAML004', width: 120, title: '赠品规格'}
            , {field: 'GWDCZ005', width: 80, title: '赠品价格'}
            , {field: 'GWDCZ006', width: 80, title: '赠品结算价', hide: true}
        ]],
        callObj,
        listData = null,
        table, gwdc004Table, gwdczTable
    ;

    var Gwdc004Deatil = app.Module.extend({
            init: function () {
                self = this;
                self._super({
                    _tag: 'gwdc004_detail'
                }, win);
            },
            initTable1: function () {
                layui.use(['table'], function () {
                    table = layui.table;
                    gwdc004Table = table.render({
                        elem: app.getByid(doc, 'gwdc004_detail1_table'),
                        id: 'gwdc004_detail1_table',
                        cols: cols1,
                        data: listData,
                        page: false,
                        height: 200
                    });
                });
            },
            initTable2: function () {
                layui.use(['table'], function () {
                    table = layui.table;
                    gwdczTable = table.render({
                        elem: app.getByid(doc, 'gwdc004_detail2_table'),
                        id: 'gwdc004_detail2_table',
                        cols: cols2,
                        data: listData,
                        //loading: true,
                        page: false,
                        height: 200
                    });
                });
            },
            table1Reload: function (data) {
                gwdc004Table.reload({
                    data: data
                });
            },
            table2Reload: function (data) {
                gwdczTable.reload({
                    data: data
                });
            },
            editData: function () {
                app.ajax({
                    xurl: 'crm/gwdc004/edit',
                    xdata: vueData.form,
                    loading: true,
                    okmsg: '组合促销价格修改成功',
                    cb: function (result) {
                        if (result.ok) {
                            app.pageModule('gwdc004').reloadTableCurr();
                            layer.close(layer.index);
                        }
                    }
                });
            },

            _call: function (tagData) {
                callObj = tagData.obj;
                app.ajax({
                    xurl: 'crm/gwdc004/listGwdc',
                    xdata: {GWDC001: callObj.GWDC001},
                    loading: true,
                    cb: function (result) {
                        listData = result.data.data;
                        self.table1Reload(listData);
                    }
                });
                app.ajax({
                    xurl: 'crm/gwdc004/listGwdcz',
                    xdata: {GWDC001: callObj.GWDC001},
                    loading: true,
                    cb: function (result) {
                        listData = result.data.data;
                        self.table2Reload(listData);
                    }
                });

                app.extendUpLow({
                    target: vueData.form,
                    res: callObj,
                    reset: true
                });

            },
            _ready: function () {
                table = layui.table;
                vueData.form = app.fields_(['crm_gwdc']);
                var vue = new Vue({
                    el: '#gwdc004_detail',
                    data: vueData,
                    watch: {},
                    methods: {
                        cancle: function () {
                            layer.close(layer.index);
                        },
                        saveData: function () {
                            this.$refs['form'].validate(function (valid) {
                                if (valid) {
                                    if (vueData.form.GWDC010 < vueData.form.GWDC009) {
                                        app.showError('截止日期不可小于生效日期!');
                                        return;
                                    }
                                    self.editData();
                                }
                            });
                        }
                    },
                    created: function () {
                        self._setEleIsReady('gwdc004_detail');
                    }
                });
                self.initTable1();
                self.initTable2();
            },
            _lazy: function () {
                this._super();
            }
        })
    ;

    return new Gwdc004Deatil();

})
;